package com.org.cys.service.impl.system;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.org.cys.dao.base.IGeneralDao;
import com.org.cys.pojo.base.Page;
import com.org.cys.service.system.UserRoleService;
import com.org.cys.util.PageData;


/**
 *	t_system_user_role Service实现类
 *	@author caiyushen
 */
@Service("userRoleServiceImpl")
public class UserRoleServiceImpl implements UserRoleService {
  
  @Resource(name="generalDao")
  private IGeneralDao generalDao;
  
  public static String XMLMapper = "UserRoleMapper";
  
 /**
  * 保存UserRole
  * @param PageData
  * @throws Exception
  * */
  @Override
  public void save(PageData pd) throws Exception{
	  generalDao.save(XMLMapper+".save",pd);
  }
  
  /**
   * 根据userId批量插入UserRole
   * @param userId 用户主键
   * @param dataList 数据集
   * @throws Exception 
   * */
  public void saveBatchByUserId(List<PageData> dataList,Long userId) throws Exception{
	  deleteByUserId(userId);//先删除之前关联数据再重新添加新的关联数据
	  generalDao.batchSave(XMLMapper+".saveBatch", dataList);
  }
  
  /**
   * 根据roleId批量插入UserRole
   * @param roleId 角色主键
   * @param dataList 数据集
   * @throws Exception 
   * */
  public void saveBatchByRoleId(List<PageData> dataList,Long roleId) throws Exception{
	  deleteByRoleId(roleId);//先删除之前关联数据再重新添加新的关联数据
	  generalDao.batchSave(XMLMapper+".saveBatch", dataList);
  }
  
 /**
  * 根据userId获取UserRole
  * @param userId 用户主键
  * @throws Exception 
  * */
  @Override
  public List<PageData> getListByUserId(Long userId) throws Exception{
	  return (List<PageData>)generalDao.findForList(XMLMapper+".getListByUserId", userId);
  }

 /**
  * 根据roleId获取UserRole
  * @param roleId 角色主键
  * @throws Exception 
  * */
  @Override
  public List<PageData> getListByRoleId(Long roleId) throws Exception{
	  return (List<PageData>)generalDao.findForList(XMLMapper+".getListByRoleId", roleId);
  }

 /**
   * 根据userId删除UserRole
   * @param userId 用户主键
   * @throws Exception  
   * */
  public void deleteByUserId(Long userId) throws Exception{
	  generalDao.delete(XMLMapper+".deleteByUserId",userId);
  }
  
  /**
	* 根据userIds批量删除UserRole
	* @params ArrayDATA_IDS 用户主键数组
	* */
   public void deleteByUserIds(String[] ArrayDATA_IDS) throws Exception{
	   generalDao.delete(XMLMapper+".deleteByUserIds",ArrayDATA_IDS);
   }

 /**
   * 根据roleId删除UserRole
   * @param roleId 角色主键
   * @throws Exception  
   * */
  public void deleteByRoleId(Long roleId) throws Exception{
	  generalDao.delete(XMLMapper+".deleteByRoleId",roleId);
  }
  
  /**
	* 根据roleIds批量删除UserRole
	* @params ArrayDATA_IDS 角色主键数组
	* */
  public void deleteByRoleIds(String[] ArrayDATA_IDS) throws Exception{
	  generalDao.delete(XMLMapper+".deleteByRoleIds",ArrayDATA_IDS);
  }
  
}